﻿
$(document).ready(function() {
    JSUtility.url = '../Handler/AjaxHandle.ashx';
    JSUtility.param = { AssemblyName: "OA.Bll.Personnel", ClassName: "OA.Bll.Personnel.TrainingPresenter", Method: "Paged", Options: { } };
    top.autoResize({ dataGrid: '#Grid', callback: InitTraininglist, par: { }, method: 'Paged' });
    $('#btnSubmit,#btnCancel').linkbutton();

    JSUtility.window_edit_form = $("#TrainingWin").find("form");
    JSUtility.window_edit = $("#TrainingWin");
    $("#btnAdd").bind("click", JSUtility.add);
    $("#btnDel").click(JSUtility.del);
    $("#btnEdit").bind("click", function() {
        //        var rows = $("#Grid").datagrid('getSelections');
        //        var num = rows.length;
        //        if (num == 0) {
        //            $.messager.alert('提示', '请选择一条记录进行操作!', 'info');
        //            return;
        //        } else {
        //            $("#IsExceptional").prop("checked", rows[0].);
        //        }
        JSUtility.update();
    });
    $("#btnRefersh").click(function() {
        $('#Grid').datagrid('reload');
    });
    $("#btnSubmit").click(function() {
        //        JSUtility.param.Options["EmployeeId"] = $("#EmployeeId").combotree('getValue');
        JSUtility.save();
    });
    $('#btnCancel').click(JSUtility.close);
    $("#EmployeeId").combotree({
        multiple: true,
        onClick: function(node) {
            if (node.attributes != undefined) {
                var text = $("#EmployeeId").combotree("getText");
                $("#EmployeeId").combotree("setText", text + ";" + node.text);
            } else {
                $("#EmployeeId").combotree("setText", null);
                $("#EmployeeId").combotree("setValue", null);
            }

            //            if (node.attributes == null || node.attributes == 'undefined') {
            //                // $.messager.alert('系统提示', '此项不可选', 'info');
            //                $("#EmployeeId").combotree("setValue", null);
            //                $("#EmployeeId").combotree("setText", null);
            //            } else {
            //                $("#EmployeeId").combotree("setValue", node.attributes["ProjectNum"]);
            //                $("#" + comboId).combotree("setText", node.text);
            //                $("#" + comboId).combotree("hidePanel");
            //            }
        }
    });
    $("#btnEmployee").click(function() {


        var rows = $("#Grid").datagrid('getSelections');
        var num = rows.length;
        if (num == 0) {
            $.messager.alert('提示', '请选择一条记录进行操作!', 'info');
            return;
        } else {
        self.parent.addTab("参训人员管理", "../Personnel/TrainPerson.htm?Id=" + rows[0].Id, "icon-sys");
        }
    });
});

function InitTraininglist(op, method, size) {
    var p = JSUtility.param;
    JSUtility.grid = $('#Grid').datagrid({
        width: size.width,
        height: size.height,
        pageSize: Math.round(size.height / 25),
        pageList: [Math.round(size.height / 25)],
        striped: true,
        queryParams: { "json": $.toJSON(p) },
        url: JSUtility.url,
        singleselect: true
    });
}